home *** CD-ROM | disk | FTP | other *** search
- Path: damage.usa1.net!news
- From: Kin Chan <firstian@usa1.com>
- Newsgroups: comp.lang.c++
- Subject: Constructor of Matrix class
- Date: Wed, 10 Jan 1996 12:32:29 -0500
- Organization: USAinternet, Inc.
- Message-ID: <30F3F82D.3A9B@usa1.com>
- NNTP-Posting-Host: wmn1-142.usa1.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0b4 (Macintosh; I; PPC)
-
- Hi,
- I wrote a simple matrix class for my own use, with all the
- arithmetic operators overloaded. I have a question about writing a
- constructor. The class declaration looks something like this
-
- class matrix {
- public:
- matrix(int row=0, int col=0);
- ~matrix
- ...
- private:
- int row,col;
- double *elemptr
- };
-
- Based on the row and col given to the constructor, the constructor
- will allocate the correct amount of memory to elemptr. However, I
- have not been able to come up with a way to initialize all the
- elements of the matrix during the constructor call. The only thing
- that I can do now is to call the operator() that I overloaded to
- access the elements one by one, which is very cumbersome for, say, a
- 9*9 matrix, which I use all the time. Basically, I wish I can do
- something like
-
- matrix M(2,2,{1.0,2.0,3.0,4.0});
-
- Like in MapleV. How can I simulate that?
-
- Thanks
-